package org.vectrics.graphics;

import org.vectrics.SystemException;
import org.vectrics.common.util.StringUtils;
import org.vectrics.struts.VectricsTagSupport;

/**
 * @author mmoore
 */
public class DynaGraphicButtonTag extends VectricsTagSupport {

	private static final long serialVersionUID = 6684874644196481829L;

	private String code = null;
    private String value = null;
    private String name = null;
    private String href = null;
    private String caption = null;
    private String phraseCode = null;
    private String paramName = null;
    private String paramValue = null;
    private String paramName2 = null;
    private String paramValue2 = null;
    private String paramName3 = null;
    private String paramValue3 = null;
    private String elementId = null;

    /**
     * 
     */
    public DynaGraphicButtonTag() {
        super();
    }

    protected String makeStartTag() {
        if (name == null)
            name = value;
        if (value == null)
            value = name;
        
        String captionText = null;
        if (phraseCode != null) {
            captionText = this.getPhrase(phraseCode);
            if (captionText == null)
                throw new SystemException("Could not find phrase code for button, phrase code = " + phraseCode);
        } else { 
            captionText = this.caption;
        }
        
        StringBuffer html = new StringBuffer();
        html.append("<a href=\"");
        html.append(this.getHref());
        if ((this.paramName != null) && (this.paramName.trim().length() > 0)) {
        	html.append("?" + paramName + "=" + paramValue);
        }
        if ((this.paramName2 != null) && (this.paramName2.trim().length() > 0)) {
        	html.append("&" + paramName2 + "=" + paramValue2);
        }
        if ((this.paramName3 != null) && (this.paramName3.trim().length() > 0)) {
        	html.append("&" + paramName3 + "=" + paramValue3);
        }
        html.append("\">");
        html.append("<img ");
        String imageSource = this.getContextPath() + "/dynagraphic/button.jpg?code=" + code 
        	+ "&caption=" + captionText;
 

        html.append("src=\"");
        html.append(imageSource);
        html.append("\" border=\"0\" ");
        
        if (StringUtils.isNullOrBlank(this.getElementId()) == false) {
	        html.append("id=\"");
	        html.append(this.getElementId());
	        html.append("\" ");
        }
        
        html.append(">");
        html.append("</a>");
        
        return(html.toString());
    }

    
    
    /**
     * @return Returns the caption.
     */
    public String getCaption() {
        return caption;
    }
    /**
     * @param caption The caption to set.
     */
    public void setCaption(String caption) {
        this.caption = caption;
    }
    /**
     * @return Returns the code.
     */
    public String getCode() {
        return code;
    }
    /**
     * @param code The code to set.
     */
    public void setCode(String code) {
        this.code = code;
    }
    /**
     * @return Returns the name.
     */
    public String getName() {
        return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return Returns the value.
     */
    public String getValue() {
        return value;
    }
    /**
     * @param value The value to set.
     */
    public void setValue(String value) {
        this.value = value;
    }
    
    
    /**
     * @return Returns the phraseCode.
     */
    public String getPhraseCode() {
        return phraseCode;
    }
    /**
     * @param phraseCode The phraseCode to set.
     */
    public void setPhraseCode(String phraseCode) {
        this.phraseCode = phraseCode;
    }
    
    
	/**
	 * @return Returns the href.
	 */
	public String getHref() {
		return href;
	}
	/**
	 * @param href The href to set.
	 */
	public void setHref(String href) {
		this.href = href;
	}
	
	/**
	 * @return Returns the paramName.
	 */
	public String getParamName() {
		return paramName;
	}
	/**
	 * @param paramName The paramName to set.
	 */
	public void setParamName(String paramName) {
		this.paramName = paramName;
	}
	/**
	 * @return Returns the paramValue.
	 */
	public String getParamValue() {
		return paramValue;
	}
	/**
	 * @param paramValue The paramValue to set.
	 */
	public void setParamValue(String paramValue) {
		this.paramValue = paramValue;
	}
	/**
	 * @return Returns the paramName2.
	 */
	public String getParamName2() {
		return paramName2;
	}
	/**
	 * @param paramName2 The paramName2 to set.
	 */
	public void setParamName2(String paramName2) {
		this.paramName2 = paramName2;
	}
	/**
	 * @return Returns the paramName3.
	 */
	public String getParamName3() {
		return paramName3;
	}
	/**
	 * @param paramName3 The paramName3 to set.
	 */
	public void setParamName3(String paramName3) {
		this.paramName3 = paramName3;
	}
	/**
	 * @return Returns the paramValue2.
	 */
	public String getParamValue2() {
		return paramValue2;
	}
	/**
	 * @param paramValue2 The paramValue2 to set.
	 */
	public void setParamValue2(String paramValue2) {
		this.paramValue2 = paramValue2;
	}
	/**
	 * @return Returns the paramValue3.
	 */
	public String getParamValue3() {
		return paramValue3;
	}
	/**
	 * @param paramValue3 The paramValue3 to set.
	 */
	public void setParamValue3(String paramValue3) {
		this.paramValue3 = paramValue3;
	}

	public String getElementId() {
		return elementId;
	}

	public void setElementId(String elementId) {
		this.elementId = elementId;
	}
	
	
}
